package com.ctgu.tengyun.service.saleorder.impl;

import com.ctgu.tengyun.dao.mybatis.SaleOrderRecordMapper;
import com.ctgu.tengyun.domain.SaleOrderRecord;
import com.ctgu.tengyun.domain.SaleOrderRecordExample;
import com.ctgu.tengyun.service.saleorder.SaleOrderRecordService;
import com.ctgu.tengyun.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by liaoweizhi on 2019/8/7.
 */
@Service
public class SaleOrderRecordServiceImpl implements SaleOrderRecordService {

    @Resource
    private SaleOrderRecordMapper mapper;

    @Override
    public int insertSelective(SaleOrderRecord record) {
        return mapper.insertSelective(record);
    }

    @Override
    public Integer countSparePart(String partNo) {
        SaleOrderRecordExample example = new SaleOrderRecordExample();
        SaleOrderRecordExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(partNo)) {
            criteria.andPartNoEqualTo(partNo);
        }
        return mapper.countByExample(example);
    }

    @Override
    public List<SaleOrderRecord> selectSaleOrderList(String partNo, Integer pageNo, Integer pageSize) {
        SaleOrderRecordExample example = new SaleOrderRecordExample();
        SaleOrderRecordExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(partNo)) {
            criteria.andPartNoEqualTo(partNo);
        }

        example.setStartIndex((pageNo - 1) * pageSize);
        example.setPageSize(pageSize);

        return mapper.selectByExample(example);
    }

    @Override
    public SaleOrderRecord selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SaleOrderRecord record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int countSaleOrder(String partNo, String contactNo, Integer orderStatus) {
        return mapper.countSaleOrder(partNo, contactNo, orderStatus);
    }

    @Override
    public List<SaleOrderRecord> selectSaleOrder(String partNo, String contactNo, Integer orderStatus, Integer pageNo, Integer pageSize) {
        return mapper.selectSaleOrder(partNo, contactNo, orderStatus, (pageNo - 1) * pageSize, pageSize);
    }
}
